#! /usr/bin/env python
#-*- coding:utf-8 -*-

from utils import *
from quatrains import get_quatrains
from rhyme import RhymeEvaluator
from generate import Generator
from plan import Planner


if __name__ == '__main__':
    evaluator = RhymeEvaluator()
    '''
    print "Evaluating rule-based method ..."
    scores = []
    with codecs.open('results.txt', 'r', 'utf-8') as fin:
        line = fin.readline()
        while line:
            scores.append(evaluator.eval(split_sentences(line.strip())))
            line = fin.readline()
    print "Mean score = %f, standard deviation = %f" % (np.mean(scores), np.std(scores))
    '''
    quatrains = get_quatrains()
    print "Testing %d quatrains from the corpus." % len(quatrains)
    scores = []
    for quatrain in quatrains:
        score = evaluator.eval(quatrain['sentences'])
        scores.append(score)
    print "Mean score = %f, standard deviation = %f" % (np.mean(scores), np.std(scores))
    num = 100
    print "Testing %d poems generated by RNN ..." %num
    scores = []
    planner = Planner()
    generator = Generator()
    for _ in range(num):
        keywords = planner.plan(u'')
        assert 4 == len(keywords)
        sentences = generator.generate(keywords)
        score = evaluator.eval(sentences)
        print "score = %f" %score
        scores.append(score)
    print "Mean score = %f, standard deviation = %f" % (np.mean(scores), np.std(scores))

